﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using umbraco.interfaces;
using umbraco.cms.businesslogic.datatype;
using System.Web.UI;

namespace Umb.SimpleWebsite.Shared.DataTypes
{
    public class BaseFTypeEditor:WebControl
    {
        public virtual bool ShowLabel { get { return true; } }
        public virtual bool TreatAsRichTextEditor { get { return false; } }
        public virtual System.Web.UI.Control Editor { get { return this; } }

        public IData Data{get;set;}
        public virtual String DataToShow
        {
            get { return this.Data.Value == null ? "" : this.Data.Value.ToString(); }
        }
        public AbstractDataEditor BaseFType{get;set;}
        protected TextBox txtInnerData;//visualdatacontainer

        public PreValue PreValue
        {
            get {
                return  PreValueEditor.PreValue;                
            }
        }
        public BaseFTypePreValueEditor PreValueEditor
        {
            get { return (BaseFTypePreValueEditor)BaseFType.PrevalueEditor; }
        }
        
        
        public BaseFTypeEditor(IData internalData, AbstractDataEditor baseFType)
        {
            Data = internalData;
            BaseFType = baseFType;
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnLoad(e);
            EnsureChildControls();            
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();            
            txtInnerData = new TextBox() { ID = this.ID + "txtInnerData", CssClass = "exdfld_resdata", Text = DataToShow };
            this.Controls.Add(txtInnerData);

        }

  


        public virtual void Save()
        {
            Data.Value = txtInnerData.Text;
        }



        
    }
}
